﻿namespace HuwmanCode

open System
open HuwmanCode
open NUnit.Framework
open FsUnit

[<TestFixture>]
type ``Array ``() =
    [<Test>]
    member this.``Array.nth - computes correct result``() =
        [|0;1;2|] |> Array.nth 1 |> should equal 1

    [<Test>]
    member this.``Array.nth - invalid index results in exn``() =
        let exnThrown = ref false
        try
            [|0;1;2|] |> Array.nth 3 |> ignore
        with _ -> exnThrown := true
        !exnThrown |> should be True

    [<Test>]
    member this.``Array.nthOrNone - computes correct result``() =
        [|0;1;2|] |> Array.nthOrNone 1 |> Option.isSome |> should be True
        [|0;1;2|] |> Array.nthOrNone 1 |> Option.get |> should equal 1

    [<Test>]
    member this.``Array.nthOrNone - invalid index results in None``() =
        [|0;1;2|] |> Array.nthOrNone 3 |> Option.isNone |> should be True

    [<Test>]
    member this.``Array.nthFromEnd - computes correct result``() =
        [|0;1;2|] |> Array.nthFromEnd 1 |> should equal 1

    [<Test>]
    member this.``Array.nthFromEnd - invalid index results in exn``() =
        let exnThrown = ref false
        try
            [|0;1;2|] |> Array.nth 3 |> ignore
        with _ -> exnThrown := true
        !exnThrown |> should be True

    [<Test>]
    member this.``Array.nthFromEndOrNone - computes correct result``() =
        [|0;1;2|] |> Array.nthFromEndOrNone 1 |> Option.isSome |> should be True
        [|0;1;2|] |> Array.nthFromEndOrNone 1 |> Option.get |> should equal 1

    [<Test>]
    member this.``Array.nthFromEndOrNone - invalid index results in None``() =
        [|0;1;2|] |> Array.nthFromEndOrNone 3 |> Option.isNone |> should be True